package com.ss.android.image;

import android.support.v4.view.ViewPager;

import com.ss.android.image.model.ImageInfo;

import pl.droidsonroids.gif.GifDrawable;

final class p extends ViewPager.SimpleOnPageChangeListener {
    private final n a;

    p(n arg1) {
        this.a = arg1;
    }

    public final void onPageSelected(int position) {
        Object v3 = null;
        n v5 = this.a;
        if (v5.mImagePager != null) {
            v5.a(position);
            int v0 = v5.j;
            v5.j = position;
            if (v0 < 0) {
                return;
            }

            if (v0 < v5.mFullPagerAdapter.getCount()) {
                ImageInfo v6 = v5.mFullPagerAdapter.b(v0);
                ImageInfo v7 = v5.mFullPagerAdapter.b(position);
                if (v6 == null) {
                    return;
                }

                if (v7 == null) {
                    return;
                }

                int v8 = v5.mImagePager.getChildCount();
                int v4 = 0;
                Object v1 = v3;
                Object v2 = v3;
                while (v4 < v8) {
                    Object v0_1 = v5.mImagePager.getChildAt(v4).getTag();
                    if (!(v0_1 instanceof com.ss.android.image.n.b)) {
                        v0_1 = v3;
                    }

                    if (v0_1 != null) {
                        if (((com.ss.android.image.n.b) v0_1).a == v6) {
                            v2 = v0_1;
                        }

                        if (((com.ss.android.image.n.b) v0_1).a != v7) {
                            v0_1 = v1;
                            v1 = v2;
                        } else {
                            v1 = v2;
                        }
                    } else {
                        label_68:
                        v0_1 = v1;
                        v1 = v2;
                    }

                    ++v4;
                    v2 = v1;
                    v1 = v0_1;
                }

                if (v2 != null && ((com.ss.android.image.n.b) v2).mFullImage.getDrawable() != null) {
                    ((com.ss.android.image.n.b) v2).mFullImage.b(1f, 300f);
                }

                if (v1 == null) {
                    return;
                }

                if (((com.ss.android.image.n.b) v1).mFullImage.getDrawable() == null) {
                    return;
                }

                if (!(((com.ss.android.image.n.b) v1).mFullImage.getDrawable() instanceof GifDrawable)) {
                    return;
                }

                try {
                    GifDrawable.a(((GifDrawable) ((com.ss.android.image.n.b) v1).mFullImage.getDrawable()).c);
                    ((GifDrawable) ((com.ss.android.image.n.b) v1).mFullImage.getDrawable()).start();
                } catch (Throwable v0_2) {
                }
            }
        }
    }
}

